package com.shj.web.controller;

import com.shj.model.PageRequest;
import com.shj.model.PageResult;
import com.shj.model.SysMenu;
import com.shj.service.SysPowerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;

/**
 * (SysPower)表控制层
 *
 * @author makejava
 * @since 2020-03-12 13:00:28
 */
@Controller
@RequestMapping("/system/menu")
public class SysMenuController {
    /**
     * 服务对象
     */
    @Resource
    private SysPowerService sysPowerService;

    /**
     * @description 获取数据并分页
     * @author songhuajian
     * @date 2020/3/19 17:15
     */
    @GetMapping("/list")
    @ResponseBody
    public PageResult selectPage(PageRequest pageRequest){
        return sysPowerService.findPage(pageRequest);
    }

    @GetMapping("/all")
    @ResponseBody
    public List<SysMenu> findAll() {
        return sysPowerService.findAll();
    }
    /**
     * 根据powerId获取权限信息
     */
    @PostMapping("/one")
    @ResponseBody
    public SysMenu findOne(@RequestBody HashMap<String, String> map) {
        String menuId = map.get("menuId");
        return sysPowerService.queryByPowerId(menuId);
    }

    /**
     * @description 添加权限
     * @author songhuajian
     * @date 2020/3/24 13:06
     */
    @PostMapping("/add")
    @ResponseBody
    public void addUser(@RequestBody @Valid SysMenu sysMenu) throws Exception {
        sysPowerService.insert(sysMenu);
    }

    /**
     * @description 更新权限
     * @author songhuajian
     * @date 2020/3/24 13:06
     */
    @PutMapping("/edit")
    @ResponseBody
    public void updateUser(@RequestBody @Valid SysMenu sysMenu) throws Exception {
        sysPowerService.update(sysMenu);
    }

    /**
     * @description 删除权限
     * @author songhuajian
     * @date 2020/3/24 13:06
     */
    @DeleteMapping("/delete")
    @ResponseBody
    public void delete(@RequestBody HashMap<String, String> map) throws Exception {
        String menuId = map.get("menuId");
        sysPowerService.delete(menuId);
    }

}